<% content_for :left_panel do %>
  <%= render :partial => "layouts/developer_left_panel" %>
<% end %>
<% content_for :ribbon do %>
  <% 
    ways = ["开发人员工具","数据库"]
  %>
  <%= ways.map{|item| "<li>#{item}</li>" }.join.html_safe %>
<% end %>
<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  
    <div class="row">
      <div class="col-sm-12">
        <div class="well">

          <%= simple_form_for :tables, url: admin_tables_path, :defaults => { :input_html => { :class => "form-control" } }, method: 'get', html: { class: "form-inline" } do |f| %>
            <label>表</label>
            <%= f.input_field :name, selected: params[:tables][:name], collection: @models.map(&:to_s).sort, label: false, prompt: '请选择表' %>
            <label>字段搜索</label>
            <%= f.input_field :field, value: params[:tables][:field] %> =
            <%= f.input_field :value, value: params[:tables][:value] %>
            <label>开始-结束时间</label>
            <div class="form-group string">
            <%= f.text_field :start_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:tables][:start_date] %>
            </div>
            <div class="form-group string">
            <%= f.text_field :end_date, class: "form-control datepicker", "data-dateformat" => "yy-mm-dd", value: params[:tables][:end_date] %>
            </div>
            <%= f.submit "搜索", :class => "btn btn-default"%>
          <% end %>

        </div> <!-- end well div -->

      </div>
    </div>

    <!-- row -->
    <div class="row">

      <div class="col-sm-12">
        <p class="alert alert-info fade in">
        <button class="close" data-dismiss="alert">
          ×
        </button>
        <i class="fa-fw fa fa-info"></i> <strong>提示</strong> 耗时以毫秒(ms)为单位。</p>
      </div>

      <div class="col-sm-12">
        <% if @tip %>
          <div class="alert alert-warning fade in">
            <button class="close" data-dismiss="alert">
              ×
            </button>
            <i class="fa-fw fa fa-warning"></i>
            <strong>提醒</strong> <%= @tip %>
          </div>
        <% end %>
      </div>

      <% if @error %>
      <div class="col-sm-12">
        <div class="alert alert-danger fade in">
          <button class="close" data-dismiss="alert">
            ×
          </button>
          <i class="fa-fw fa fa-times"></i>
          <strong>警告!</strong> <%= @error %>
        </div>
      </div>
      <% else %>

      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-darken" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">

          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"

          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>表记录列表</h2>
          </header>

          <!-- widget div-->
          <div>

            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
            </div>
            <!-- end widget edit box -->

            <!-- widget content -->
            <div class="widget-body no-padding">

              <p class="alert alert-info no-margin">
                <i class="fa-fw fa fa-info"></i>共有<%= @rows.total_count %>条记录
              </p>

              <table class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <% @fields.each do |field| %>
                    <th><%= field %></th>
                    <% end %>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                <% @rows.each do |row| %>
                  <tr id='row-<%= row.id %>'>
                    <% @fields.each do |field| %>
                      <td><%= row.send(field) %></td>
                    <% end %>
                    <td>
                      <% unless Rails.env == 'production' %>
                      <%= link_to('删除', admin_table_path(id: row.id, table: params[:tables][:name]), method: :delete, :class => 'btn btn-danger', remote: true, confirm: '是否确定删除?') if current_admin.can?(controller: "admin/table",action: "destroy") %>
                      <% end %>
                      <%= link_to('日志', admin_activities_path(activity: {item_type: params[:tables][:name], field: :id, value: row.id}), method: :get, target: '_blank') if current_admin.can?(controller: "admin/activities") %>
                    </td>
                  </tr>
                <% end %>
                </tbody>
              </table>
              <div class="dt-row dt-bottom-row"><div class="row"><div class="col-sm-12 text-right"><%= paginate @rows %></div></div></div>
            </div>
            <!-- end widget content -->

          </div>
          <!-- end widget div -->

        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->
      <% end %>
    </div>
  
    <!-- end row -->

  </section>
  <!-- end widget grid -->
<% end %>